package org.bonorsoft.modules.control.util;

import net.sf.json.JSONObject;

public class MessageUtils {
    private static String base_url = "http://v.juhe.cn/sms/send";//接口地址
    private static String tpl_id = "238367";//短信模板ID，请参考个人中心短信模板设置
    private static String tpl_key = "4c57ef2c04134bb7570546d6e77f90e4";//在个人中心->我的数据,接口名称上方查看

    //短信通知
    public static int SendMessage(String mobile, String tpl_value){
        String messageUrl = base_url+"?mobile="+mobile+"&tpl_id="+tpl_id+"&tpl_value="+tpl_value+"&key="+tpl_key;
        int SendCount = 0;
        String response = HttpClientUtils.doGet(messageUrl);
        try {
            JSONObject jsonObject = JSONObject.fromObject(response);
            int error_code = jsonObject.getInt("error_code");
            if (error_code == 0) {
                JSONObject result = jsonObject.getJSONObject("result");
                String sid = result.getString("sid");
                System.out.println("本次发送的唯一标示：" + sid);
                SendCount = result.getInt("fee");
            }else{
                System.out.println("调用接口失败："+ jsonObject.getString("reason"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SendCount;
    }
}
